home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / system / pubit_101.lha / pubit101 / PubIt_src.lha / PubIt.c next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  48.5 KB  |  1,588 lines

  1. /*  
  2.     PubIt V1.01     LC: 11.August 1994
  3.     Copyright © 1994 by Chris (Confusio) Rickers
  4.  
  5.     Simple tool to open a configurable public screen
  6.     and starts a specified application to run on this
  7.     screen.
  8.  
  9.     Gui created with GadToolsBox
  10.  
  11.     Compile with SAS 6.50+:
  12.  
  13.       SC Pubby.c IGNORE=154+147
  14.       SLINK   LIB:c.o LIB:Boopsi.o Pubby.o TO Pubby LIB LIB:sc.lib LIB:scm.lib LIB:amiga2.0.lib LIB:reqtoolsnb.lib
  15.  
  16.     *************************************************************************************************************
  17.  
  18.     NOTE: this source code is not PD, but you can make improvements or adjustments as you like  -- as far
  19.           as you obey the following rules:
  20.  
  21.           1)  The new code segment has to be clearly marked as such
  22.           2)  You put a note in the history file.
  23.           3)  You send me the new source for spreadings:  
  24.               *** YOU ARE NOT ALLOWED TO DISTRIBUTE THE MODIFIED PROGRAM YOURSELF ***
  25.  
  26.     *************************************************************************************************************
  27. */
  28.  
  29. #define DETAIL    0
  30. #define BLOCK     1
  31. #define TEXTP     2
  32. #define SHINE     3
  33. #define SHADOW    4
  34. #define FILL      5
  35. #define FILLTEXT  6
  36. #define BACKGR    7
  37. #define HITEXT    8
  38. #define BDETAIL   9
  39. #define BBLOCK    10
  40. #define BTRIM     11
  41.  
  42. /// Include List
  43. #include  <exec/types.h>
  44. #include  <exec/libraries.h>
  45. #include  <dos/dos.h>
  46. #include  <dos/dostags.h>
  47. #include  <intuition/intuition.h>
  48. #include  <intuition/IntuitionBase.h>
  49. #include  <intuition/screens.h>
  50. #include  <intuition/classes.h>
  51. #include  <intuition/classusr.h>
  52. #include  <intuition/imageclass.h>
  53. #include  <intuition/gadgetclass.h>
  54. #include  <graphics/gfx.h>
  55. #include  <graphics/GfxBase.h>
  56. #include  <graphics/modeid.h>
  57. #include  <graphics/gfxmacros.h>
  58. #include  <libraries/diskfont.h>
  59. #include  <libraries/reqtools.h>
  60. #include  <libraries/gadtools.h>
  61. #include  <workbench/workbench.h>
  62. #include  <workbench/startup.h>
  63.  
  64. #include  <clib/exec_protos.h>
  65. #include  <clib/intuition_protos.h>
  66. #include  <clib/graphics_protos.h>
  67. #include  <clib/diskfont_protos.h>
  68. #include  <clib/reqtools_protos.h>
  69. #include  <clib/alib_protos.h>
  70. #include  <clib/utility_protos.h>
  71.  
  72. #include  <pragmas/intuition_pragmas.h>
  73. #include  <pragmas/graphics_pragmas.h>
  74. #include  <pragmas/utility_pragmas.h>
  75.  
  76. #include  <proto/exec.h>
  77. #include  <proto/dos.h>
  78. #include  <proto/diskfont.h>
  79. #include  <proto/icon.h>
  80. #include  <proto/gadtools.h>
  81.  
  82. #include  <string.h>
  83. #include  <stdio.h>
  84. #include  <stdlib.h>
  85. #include  <string.h>
  86. #include  <math.h>
  87.  
  88. #include  "PubIt.h"                        //  GadToolsBox Header File
  89. ///
  90.  
  91. /// Structures  and Variables
  92.  
  93.   // Structures
  94. extern struct ExecBase   *SysBase;
  95. extern struct DosLibrary *DOSBase;
  96. struct WBStartup         *IconArgs;
  97. struct Library           *IntuitionBase;
  98. struct GfxBase           *GfxBase;
  99. struct Library           *DiskfontBase;
  100. struct Library           *IconBase;
  101. struct Library           *GadToolsBase;
  102. struct Library           *ReqToolsBase;
  103. struct Window            *syswin   = NULL;
  104. struct Process           *PubbyProc = NULL;
  105.  
  106.   //  GadToolsBox Structures 'n vars...
  107.  
  108. APTR                      VisualInfo;
  109. struct  Screen            *Scr = NULL;
  110. UBYTE                     *PubScreenName = NULL;
  111. struct  Window            *PubbyMainWnd = NULL,
  112.                           *DriPenAdjustWnd  = NULL,
  113.                           *ApplicationDataWnd = NULL;
  114. struct  Gadget            *DriPenAdjustGList  = NULL,
  115.                           *ApplicationDataGList = NULL;
  116. struct  Menu              *PubbyMainMenus = NULL;
  117. struct  IntuiMessage       PubbyMainMsg,
  118.                            DriPenAdjustMsg,
  119.                            ApplicationDataMsg;
  120. struct  Gadget            *DriPenAdjustGadgets[3],
  121.                           *ApplicationDataGadgets[5];
  122. struct  NewGadget         DriPenAdjustNGad[],
  123.                           ApplicationDataNGad[];
  124. struct  IClass            *getClass = NULL;
  125. struct  _Object           *getImage = NULL;
  126. struct  TextAttr          *Font, Attr;
  127.  
  128. struct  TextFont          *PubbyMainFont = NULL;
  129. struct  TextFont          *DriPenAdjustFont = NULL;
  130. struct  TextFont          *ApplicationDataFont = NULL;
  131. struct  TextFont          *ScrFont =  NULL;
  132. struct  TextAttr          ScrAttr = {
  133.   "helvetica.font                ",
  134.   13,
  135.   FS_NORMAL,
  136.   FPB_ROMFONT|FPB_DISKFONT,
  137. };
  138.  
  139.   //  GUI Data...
  140.  
  141. UBYTE *driadjust_pens1Labels[] = {
  142.         (UBYTE *)"Detail", (UBYTE *)"Block",  (UBYTE *)"Text", (UBYTE *)"Shine", (UBYTE *)"Shadow", (UBYTE *)"Fill",
  143.         (UBYTE *)"FillText", (UBYTE *)"Background", (UBYTE *)"HighlightText", (UBYTE *)"BarDetail", (UBYTE *)"BarBlock",
  144.         (UBYTE *)"BarTrim", NULL };
  145.  
  146. struct NewMenu PubbyMainNewMenu[] = {
  147.         NM_TITLE, (STRPTR)"PubIt-Project",    NULL,         0, NULL, NULL,
  148.         NM_ITEM, (STRPTR)"Screen Mode...",    (STRPTR)"m",  0, 0L, (APTR)PubbyMainsmode,
  149.         NM_ITEM, (STRPTR)"Color-Palette...",  (STRPTR)"p",  0, 0L, (APTR)PubbyMaincpalette,
  150.         NM_ITEM, (STRPTR)"Define DriPens...", (STRPTR)"d",  0, 0L, (APTR)PubbyMaindripens,
  151.         NM_ITEM, (STRPTR)"Font...",           (STRPTR)"f",  0, 0L, (APTR)PubbyMainfont,
  152.         NM_ITEM, (STRPTR)NM_BARLABEL,         NULL,         0, 0L,  NULL,
  153.         NM_ITEM, (STRPTR)"Set Application...",(STRPTR)"a",  0, 0L, (APTR)PubbyMainappdata,
  154.         NM_ITEM, (STRPTR)NM_BARLABEL,         NULL,         0, 0L, NULL,
  155.         NM_ITEM, (STRPTR)"About",             NULL,         0, 0L, (APTR)PubbyMainabout,
  156.         NM_ITEM, (STRPTR)NM_BARLABEL,         NULL,         0, 0L, NULL,
  157.         NM_ITEM, (STRPTR)"Save...",           (STRPTR)"s",  0, 0L, (APTR)PubbyMainsave,
  158.         NM_ITEM, (STRPTR)NM_BARLABEL,         NULL,         0, 0L, NULL,
  159.         NM_ITEM, (STRPTR)"Quit.",             (STRPTR)"q",  0, 0L, (APTR)PubbyMainquit,
  160.         NM_END,  NULL,                        NULL,         0, 0L, NULL };
  161.  
  162. UWORD DriPenAdjustGTypes[] = { PALETTE_KIND, CYCLE_KIND, BUTTON_KIND };
  163.  
  164. UWORD ApplicationDataGTypes[] = { STRING_KIND, INTEGER_KIND, INTEGER_KIND, BUTTON_KIND, GENERIC_KIND };
  165.  
  166. struct NewGadget DriPenAdjustNGad[] = {
  167.         48, 30, 130, 26, (UBYTE *)"_Color",   NULL, GD_driadjust_palette, PLACETEXT_LEFT, NULL, (APTR)driadjust_paletteClicked,
  168.         48, 12, 128, 16, (UBYTE *)"_Pens",    NULL, GD_driadjust_pens,    PLACETEXT_LEFT, NULL, (APTR)driadjust_pensClicked,
  169.         147, 64, 56, 14, (UBYTE *)"_OK",      NULL, GD_driadjust_OK,      PLACETEXT_IN,   NULL, (APTR)driadjust_OKClicked
  170. };
  171.  
  172. struct NewGadget ApplicationDataNGad[] = {
  173.         76, 12, 97, 15,  (UBYTE *)"_Path/File:",  NULL, GD_app_path,    PLACETEXT_LEFT, NULL, (APTR)app_pathClicked,
  174.         76, 29, 118, 15, (UBYTE *)"_Stack:",      NULL, GD_Gadget12,    PLACETEXT_LEFT, NULL, (APTR)Gadget12Clicked,
  175.         76, 46, 118, 15, (UBYTE *)"_Priority:",   NULL, GD_apppri,      PLACETEXT_LEFT, NULL, (APTR)apppriClicked,
  176.         138, 70, 56, 14, (UBYTE *)"_OK",          NULL, GD_appok,       PLACETEXT_IN,   NULL, (APTR)appokClicked,
  177.         176, 13, 20, 14, NULL,                    NULL, GD_appgetfile,  0,              NULL, (APTR)appgetfileClicked
  178. };
  179.  
  180. ULONG DriPenAdjustGTags[] = {
  181.         (GTPA_Depth), 8, (GTPA_Color), 1, (GTPA_ColorOffset), 0, (GT_Underscore), '_', (TAG_DONE),
  182.         (GTCY_Labels), (ULONG)&driadjust_pens1Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  183.         (GT_Underscore), '_', (TAG_DONE)
  184. };
  185.  
  186. ULONG ApplicationDataGTags[] = {
  187.         (GTST_String), (ULONG)"My Application!", (GTST_MaxChars), 180, (GT_Underscore), '_', (TAG_DONE),
  188.         (GA_TabCycle), FALSE, (GTIN_Number), 4096, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  189.         (GA_TabCycle), FALSE, (GTIN_Number), 0, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  190.         (GT_Underscore), '_', (TAG_DONE),
  191.         (TAG_DONE)
  192. };
  193.  
  194.   //  Variables
  195.  
  196. UBYTE PubScrName[20] =  "PUBSCR.1";
  197. UBYTE PubTitle[100]   =  "PubIt, Copyright © 1994 by Chris (Confusio) Rickers";
  198. UBYTE AppName[200];
  199. LONG  AppPri=0;
  200. ULONG AppStack=4096,  Width=640, Height=200, Depth=2, ID  = DEFAULT_MONITOR_ID|LORES_KEY;
  201. UWORD DriPens[13] = { 0,1,1,2,1,3,2,0,2,1,2,1,};
  202. UBYTE TTARRAY[12][20] = { { "DETAIL"},  { "BLOCK"},  {"TEXT"}, { "SHINE"},
  203.                           { "SHADOW"},  { "FILL"} , { "FILLTEXT"  },
  204.                           { "BACKGROUND"} ,{  "HIGHLIGHTTEXT"} ,
  205.                           { "BARDETAIL" },  { "BARFILL"}  , { "BARTRIM" } 
  206.                         };
  207. UBYTE FONTNAME[40]  = "topaz.font";
  208. UWORD FONTSIZE      = 8;
  209. int   SelectedDriPen  = 0;
  210. BOOL  INTERLEAVED = FALSE,  _SHANGHAI  = FALSE;
  211. UWORD OldPubModes = NULL;
  212. UBYTE App_HomeDir[200];
  213. UBYTE App_CurrDir[200];
  214. UBYTE App_Args[200];
  215. BOOL  FQUIT=FALSE;
  216. BOOL  FWQUIT=FALSE;
  217. BOOL  SHOWNAME=TRUE;
  218. static UBYTE  formstr[200];
  219.  
  220.   //  GadToolsBox
  221.  
  222. UWORD PubbyMainLeft = 0,  
  223.       PubbyMainTop = 10,
  224.       PubbyMainWidth  = 100,
  225.       PubbyMainHeight = 100;
  226. UWORD DriPenAdjustLeft = 23,
  227.       DriPenAdjustTop = 63,
  228.       DriPenAdjustWidth = 213,
  229.       DriPenAdjustHeight = 82;
  230. UWORD ApplicationDataLeft = 70,
  231.       ApplicationDataTop  = 45,
  232.       ApplicationDataWidth  = 202,
  233.       ApplicationDataHeight = 90;
  234.  
  235. UBYTE *PubbyMainWdt = NULL;             //  will become a borderless backdrop window, so no title
  236. UBYTE *DriPenAdjustWdt  = (UBYTE*)"Define DriPens...";
  237. UBYTE *ApplicationDataWdt = (UBYTE*)"Application Data..:";
  238.  
  239. UWORD  FontX, FontY;
  240. UWORD  OffX, OffY;
  241.  
  242.     //  static, Arrghhh!!!
  243.  
  244. UBYTE mycolors[768]  =
  245.   {
  246.     8,8,8,
  247.     0,0,0,
  248.     15,15,15,
  249.     6,9,13,
  250.     14,0,2,
  251.     2,15,2,
  252.     14,8,0,
  253.     0,0,0,
  254.   };              //  ...
  255.  
  256. ///
  257.  
  258. /// Prototypes
  259.  
  260.   //  Private Prototypes
  261.  
  262. void  openall( void );                    //  Opens screen and makes it public, after having read the prefs for that screen.
  263. void  closeall( void );
  264. static BOOL ReplaceTool(UBYTE **ttarr, UBYTE *ts, UBYTE *rps);
  265. void  RenderLine(struct RastPort  *,  UWORD,  UWORD, UWORD, UWORD );
  266. int   updatescreen( void );
  267. void  setcolors( void );
  268. void  getcolors( void );
  269. int   RunApp( void );
  270.  
  271.   //  GadToolsBox Prototypes
  272.  
  273. extern  Class         *initGet( void );
  274. static  UWORD          ComputeX( UWORD );
  275. static  UWORD          ComputeY( UWORD );
  276. static  void           ComputeFont( UWORD, UWORD );
  277. int                    SetupScreen( void );
  278. int                    CloseDownScreen( void );
  279. int                    HandlePubbyIDCMP( void );
  280. int                    OpenPubbyMainWindow( void );
  281. void                   ClosePubbyMainWindow( void );
  282. int                    PubbyMainCloseWindow( void );
  283. int                    DriPenAdjustCloseWindow( void );
  284. int                    ApplicationDataCloseWindow( void );
  285. ///
  286.  
  287. UBYTE vstr[]  = "$VER: PubIt V1.01, LC: 29.08.1994";
  288.  
  289. /// setcolors( )
  290. void setcolors(void)
  291. {
  292.  short i;
  293.  
  294.  for(i=0;i< pow(2.0,(double)Depth) ;i++)
  295.   SetRGB4(&Scr->ViewPort,(long)i,(long)mycolors[i*3],
  296.     (long)mycolors[i*3+1],(long)mycolors[i*3+2]);
  297. }
  298. ///
  299.  
  300. /// getcolors( )
  301. void getcolors(void)
  302. {
  303.   long color;
  304.   short i;
  305.  
  306.     for(i=0;i<pow(2.0,(double)Depth);i++)
  307.      {
  308.        color=GetRGB4(Scr->ViewPort.ColorMap,(long)i);
  309.        mycolors[i*3]=(  color>>8  ) & 0xf;
  310.        mycolors[i*3+1]=(  color>>4  ) & 0xf;
  311.        mycolors[i*3+2]= color & 0xf;
  312.      }
  313. }
  314. ///
  315.  
  316. /// RenderLine( )
  317. void RenderLine(struct  RastPort  *rp, UWORD x1, UWORD y1, UWORD x2, UWORD y2)
  318. {
  319.   SetAPen(rp,DriPens[3]);   //  shine pen
  320.   if(x1!=x2 && y2!=y2)
  321.     return;
  322.   if(x1==x2){
  323.     SetAPen(rp,DriPens[4]);     //  shadow pen
  324.     Move(rp,x1,y1);
  325.     Draw(rp,x1,y2);
  326.     SetAPen(rp,DriPens[3]); //  shine pen
  327.     Move(rp,x1+1,y2);
  328.     Draw(rp,x1+1,y1+1);
  329.     return;
  330.   }
  331.   else{
  332.     Move(rp,x1,y1);
  333.     Draw(rp,x2,y2);
  334.     Draw(rp,x2,y2-1);
  335.     SetAPen(rp,DriPens[4]); //  shadow pen
  336.     Move(rp,x2-1,y2-1);
  337.     Draw(rp,x1,y1-1);
  338.     Draw(rp,x1,y1);
  339.     return;
  340.   }
  341. }
  342. ///
  343.  
  344. /// RunApp( )
  345. int RunApp( void )
  346. {
  347.   long error  = NULL;
  348.   UBYTE comString[500];
  349.   BPTR  nilptr  = NULL;
  350.  
  351.   if(strlen(AppName) <=  0)
  352.     return((int) 0 );
  353.  
  354.   nilptr = Open("NIL:",MODE_NEWFILE); //  avoid error-output windows on wb
  355.  
  356.   sprintf(comString, "%s %s\n",AppName,App_Args);
  357.   error=SystemTags(comString,
  358.                     NP_StackSize, AppStack,
  359.                     NP_Name,  "PubIt-Application",
  360.                     NP_Priority, AppPri,
  361.                     SYS_Output, nilptr,
  362.                     TAG_END);
  363.  
  364.   Close(nilptr);
  365.   nilptr  = NULL;
  366.  
  367.   if(error!=0){
  368.     if(error==-1)
  369.       rtEZRequestTags("PubIt-Error:\n"
  370.         "Unable to launch application!","Shit!",
  371.         0l,0l,RT_PubScrName,PubScrName,TAG_END);
  372.     else
  373.       rtEZRequestTags("PubIt-Error:\n"
  374.         "Application returned an error!","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  375.   }
  376.  
  377.    /*
  378.     app_process = CreateNewProcTags(NP_Seglist, seglist,
  379.             //        NP_CurrentDir, App_CurrDir,
  380.             //        NP_HomeDir, App_HomeDir,
  381.             //        NP_Arguments, App_Args,
  382.                     TAG_END);
  383.   }
  384.   else
  385.     app_process = CreateNewProcTags(NP_Seglist, seglist,
  386.              //       NP_CurrentDir, App_CurrDir,
  387.                     NP_StackSize, AppStack,
  388.              //       NP_Name,  "PubIt-Application",
  389.              //       NP_Priority, AppPri,
  390.              //       NP_HomeDir, App_HomeDir,
  391.                     TAG_END);
  392.  
  393.  
  394.   if( NOT app_process ) {
  395.     rtEZRequestTags("PubIt-Error:\nError creating new application process!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  396.     if(NOT UnLoadSeg( seglist ))
  397.       rtEZRequestTags("PubIt-Error:\n"
  398.         "Unable to Unload Seglist of your \n"
  399.         "application --> Memory Trash","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  400.     return((int)0);   //  no application started
  401.   }
  402.   rtEZRequestTags("Application Runs!","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  403.   */
  404.  
  405.   return((int)1);  //  application should run asynch, now.
  406. }
  407. ///
  408.  
  409. /// ComputeX( )
  410. static UWORD  ComputeX( UWORD value )
  411. { return( (UWORD) (((  FontX * value ) + 3 ) / 6 ));
  412. }
  413. ///
  414.  
  415. /// ComputeY( )
  416. static UWORD  ComputeY( UWORD value )
  417. { return((UWORD) ((( FontY * value ) +5 ) / 11 ));
  418. }
  419. ///
  420.  
  421. /// ComputeFont( )
  422. static void ComputeFont(  UWORD width, UWORD height )
  423. {
  424.  
  425.   if(strlen(FONTNAME)<=0)
  426.     goto UseTopaz;
  427.  
  428.   Font = &ScrAttr;
  429.   Font->ta_Name = FONTNAME;
  430.   Font->ta_YSize  = FontY = FONTSIZE;
  431.   FontX = ScrFont->tf_XSize;
  432.  
  433.   OffX  = Scr->WBorLeft;
  434.   OffY  = Scr->RastPort.TxHeight  + Scr->WBorTop + 1;
  435.     
  436.   if ( width && height ) {
  437.     if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  438.       goto UseTopaz;
  439.     if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  440.       goto UseTopaz;
  441.     }
  442.     return;
  443.   
  444.   UseTopaz:
  445.     Font->ta_Name = (STRPTR)"topaz.font";
  446.     FontX = FontY = Font->ta_YSize = 8;
  447. }
  448. ///
  449.  
  450. /// SetupScreen( )
  451. int SetupScreen( void )
  452. {
  453.   ScrAttr.ta_Name = (STRPTR)FONTNAME;
  454.   ScrAttr.ta_YSize = (UWORD)FONTSIZE;
  455.  
  456.   if(SHOWTITLE)
  457.     sprintf(formstr, "%s     <%s>",PubTitle,PubScrName);
  458.   else
  459.     strcpy(formstr, PubTitle);
  460.   
  461.   if(!(ScrFont = (struct TextFont *)OpenDiskFont( &ScrAttr)))
  462.   {
  463.     rtEZRequestTags("PubIt-Error:\n\nUnable to open specified\n"
  464.       "font \"%s\"!","OK!",0l,ScrAttr.ta_Name,RT_PubScrName,PubScrName,TAG_END);
  465.     return((int)0);
  466.   }
  467.  
  468.   if( ! ( Scr = OpenScreenTags  ( NULL, SA_Left , 0 ,
  469.     SA_Top,         0,
  470.     SA_Width,       Width,
  471.     SA_Height,      Height,
  472.     SA_Depth,       Depth,
  473.     SA_Type,        PUBLICSCREEN,
  474.     SA_PubName,     PubScrName,
  475.     SA_DisplayID,   ID,
  476.     SA_AutoScroll,  TRUE,
  477.     SA_Overscan,    OSCAN_TEXT,
  478.     SA_Interleaved, INTERLEAVED,
  479.     SA_Pens,        &DriPens[0],
  480.     SA_Font,        &ScrAttr,
  481.     SA_Title,       formstr,
  482.     TAG_DONE ))){
  483.     return( (int) 0 );
  484.   }
  485.  
  486.   ComputeFont(  0, 0 );
  487.  
  488.   if( ! ( VisualInfo = GetVisualInfo ( Scr, TAG_DONE ))){
  489.     return( (int) 0 );
  490.   }
  491.  
  492.   if( ! ( getClass = initGet() )){
  493.     rtEZRequestTags("No getClass","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  494.     return( (int) 0 );
  495.   }
  496.  
  497.   if( ! ( getImage = NewObject( getClass, NULL, GT_VisualInfo, VisualInfo, TAG_DONE ))){
  498. #ifdef  DEBUG
  499.     rtEZRequestTags("No getImage!","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  500. #endif  //  DEBUG
  501.     return( (int) 0 );
  502.   }
  503.  
  504.   PubScreenStatus(Scr,0);
  505.   setcolors( ) ;
  506.  
  507.   if(_SHANGHAI){
  508.     SetDefaultPubScreen(PubScrName);
  509.     OldPubModes = SetPubScreenModes( SHANGHAI );
  510.   }
  511.   return( (int) 1);
  512. }
  513. ///
  514.  
  515. /// CloseDownScreen( )
  516. int CloseDownScreen( void )
  517. {
  518.   while( Scr->FirstWindow )
  519.     rtEZRequestTags("Please close all windows first,\nthen click on \"Retry!\"","Retry!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  520.  
  521.   if(_SHANGHAI){ //  this is not modified during runtime
  522.     SetPubScreenModes(  OldPubModes );
  523.     SetDefaultPubScreen(  NULL );
  524.   }
  525.  
  526.   if( getImage )
  527.     DisposeObject( getImage );
  528.   if( getClass )
  529.     FreeClass( getClass );
  530.   if( VisualInfo )
  531.     FreeVisualInfo( VisualInfo );
  532.   if( Scr )
  533.     CloseScreen( Scr );
  534.  
  535.   Scr         = NULL;
  536.   VisualInfo  = NULL;
  537.   getClass    = NULL;
  538.   getImage    = NULL;
  539.  
  540.   if(ScrFont){
  541.     CloseFont(ScrFont);
  542.     ScrFont = NULL;
  543.   }
  544.  
  545.   return( (int) 1 );
  546. }
  547. ///
  548.  
  549. /// HandlePubbyMainIDCMP( )                   TO BE OPTIMIZED
  550. int HandlePubbyMainIDCMP( void )
  551. {
  552.   struct IntuiMessage     *m;
  553.   struct MenuItem         *n;
  554.   int                     (*func)();
  555.   BOOL  running = TRUE;
  556.  
  557.   for(;;){
  558.     if((  m = GT_GetIMsg( PubbyMainWnd->UserPort ))==NULL)
  559.       WaitPort(PubbyMainWnd->UserPort);
  560.     else{
  561.       CopyMem(( char * )m, ( char * )&PubbyMainMsg, (long)sizeof( struct IntuiMessage ));
  562.  
  563.       GT_ReplyIMsg( m );
  564.       switch ( PubbyMainMsg.Class ) {
  565.         case    IDCMP_REFRESHWINDOW:
  566.                   GT_BeginRefresh( PubbyMainWnd );
  567.                   GT_EndRefresh( PubbyMainWnd, TRUE );
  568.                 break;
  569.         case    IDCMP_CLOSEWINDOW:
  570.                   return((int)(running = PubbyMainCloseWindow()));
  571.                 break;
  572.         case    IDCMP_MENUPICK:
  573.                 while( PubbyMainMsg.Code != MENUNULL ) {
  574.                   n = ItemAddress( PubbyMainMenus, PubbyMainMsg.Code );
  575.                   func = (void *)(GTMENUITEM_USERDATA( n ));
  576.                   return((int)func());
  577.                 }
  578.                 break;
  579.       } //  switch
  580.     } //  if
  581.   } //  for(;;)
  582. }
  583. ///
  584.  
  585. /// OpenPubbyMainWindow( )
  586. int OpenPubbyMainWindow( void )
  587. {
  588.   UWORD              wleft  = 0,
  589.                      wtop   = Scr->BarHeight + 2;
  590.  
  591.   PubbyMainWidth  =   100;
  592.   PubbyMainHeight =   100;
  593.  
  594.   if ( ! ( PubbyMainFont = OpenDiskFont( Font )))
  595.     return( (int) 0 );
  596.   if ( ! ( PubbyMainMenus = CreateMenus( PubbyMainNewMenu, GTMN_FrontPen, 1L, TAG_DONE )))
  597.     return( (int) 0 );
  598.  
  599.   LayoutMenus( PubbyMainMenus, VisualInfo, TAG_DONE );
  600.  
  601.   if ( ! ( PubbyMainWnd = OpenWindowTags( NULL,
  602.     WA_Left,        wleft,
  603.     WA_Top,         wtop,
  604.     WA_Width,       100,
  605.     WA_Height,      100,
  606.     WA_IDCMP,       IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  607.     WA_Flags,       WFLG_NEWLOOKMENUS|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_BACKDROP|WFLG_BORDERLESS,
  608.     WA_Title,       PubbyMainWdt,
  609.     WA_PubScreen,   Scr,
  610.     WA_PubScreenName, PubScrName,
  611.     WA_AutoAdjust,  TRUE,
  612.     WA_MinWidth,    10,
  613.     WA_MinHeight,   10,
  614.     WA_MaxWidth,    PubbyMainWidth,
  615.     WA_MaxHeight,   PubbyMainHeight,
  616.     TAG_DONE )))
  617.   return( (int) 0 );
  618.  
  619.   PubbyProc=(struct Process *)FindTask(NULL);
  620.   syswin=PubbyProc->pr_WindowPtr;
  621.   PubbyProc->pr_WindowPtr = (APTR)  PubbyMainWnd;
  622.  
  623.   SetMenuStrip( PubbyMainWnd, PubbyMainMenus );
  624.   GT_RefreshWindow( PubbyMainWnd, NULL );
  625.   return( (int) 1 );
  626. }
  627. ///
  628.  
  629. /// ClosePubbyMainWindow( )
  630. void ClosePubbyMainWindow( void )
  631. {
  632.   PubbyProc->pr_WindowPtr = syswin;
  633.  
  634.   if ( PubbyMainMenus )
  635.   {
  636.     ClearMenuStrip( PubbyMainWnd );
  637.     FreeMenus( PubbyMainMenus );
  638.     PubbyMainMenus = NULL;  
  639.   }
  640.  
  641.   if ( PubbyMainWnd  ) 
  642.   {
  643.     CloseWindow( PubbyMainWnd );
  644.     PubbyMainWnd = NULL;
  645.   }
  646.  
  647.   if ( PubbyMainFont ) 
  648.   {
  649.     CloseFont( PubbyMainFont );
  650.     PubbyMainFont = NULL;
  651.   }
  652. }
  653. ///
  654.  
  655. /// DriPenAdjustRender( )
  656. void DriPenAdjustRender( void )
  657. {
  658.   ComputeFont( DriPenAdjustWidth, DriPenAdjustHeight );
  659.   RenderLine(DriPenAdjustWnd->RPort, OffX + ComputeX( 0 ), OffY + ComputeY( 60 ), OffX+ComputeX( 213 ), OffY+ComputeY( 60 ) );
  660.   DrawBevelBox( DriPenAdjustWnd->RPort, OffX + ComputeX( 178 ),OffY + ComputeY( 30 ),ComputeX( 27 ),ComputeY( 25 ),GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
  661. }
  662. ///
  663.  
  664. /// HandleDriPenAdjustIDCMP( )                TO BE OPTIMIZED
  665. int HandleDriPenAdjustIDCMP( void )
  666. {
  667.   struct IntuiMessage     *m;
  668.   int                     (*func)();
  669.   BOOL                    running = TRUE;
  670.  
  671.   while( m = GT_GetIMsg( DriPenAdjustWnd->UserPort )) {
  672.     CopyMem(( char * )m, ( char * )&DriPenAdjustMsg, (long)sizeof( struct IntuiMessage ));
  673.     GT_ReplyIMsg( m );
  674.     switch ( DriPenAdjustMsg.Class ) {
  675.       case    IDCMP_REFRESHWINDOW:
  676.                 GT_BeginRefresh( DriPenAdjustWnd );
  677.                 DriPenAdjustRender();
  678.                 GT_EndRefresh( DriPenAdjustWnd, TRUE );
  679.               break;
  680.       case    IDCMP_CLOSEWINDOW:
  681.                 running = DriPenAdjustCloseWindow();
  682.               break;
  683.       case    IDCMP_GADGETUP:
  684.                 func = ( void * )(( struct Gadget * )DriPenAdjustMsg.IAddress )->UserData;
  685.                 running = func();
  686.                 break;
  687.     }
  688.   }
  689.   return( (int) running );
  690. }
  691. ///
  692.  
  693. /// OpenDriPenAdjustWindow( )
  694. int OpenDriPenAdjustWindow( void )
  695. {
  696.   struct NewGadget        ng;
  697.   struct Gadget   *g;
  698.   UWORD           lc, tc;
  699.   UWORD           wleft = DriPenAdjustLeft,
  700.                   wtop  = DriPenAdjustTop,
  701.                   ww, wh;
  702.  
  703.   ComputeFont( DriPenAdjustWidth, DriPenAdjustHeight );
  704.   ww = ComputeX( DriPenAdjustWidth );
  705.   wh = ComputeY( DriPenAdjustHeight );
  706.  
  707.   if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  708.   if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  709.  
  710.   if ( ! ( DriPenAdjustFont = OpenDiskFont( Font )))
  711.     return( (int) 0 );
  712.   if ( ! ( g = CreateContext( &DriPenAdjustGList )))
  713.     return( (int) 0 );
  714.  
  715.   DriPenAdjustGTags[1] = Depth;       //  this is `set only!'
  716.  
  717.   for( lc = 0, tc = 0; lc < DriPenAdjust_CNT; lc++ ) {
  718.     CopyMem((char * )&DriPenAdjustNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  719.     ng.ng_VisualInfo = VisualInfo;
  720.     ng.ng_TextAttr   = Font;
  721.     ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  722.     ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  723.     ng.ng_Width      = ComputeX( ng.ng_Width );
  724.     ng.ng_Height     = ComputeY( ng.ng_Height);
  725.     DriPenAdjustGadgets[ lc ] = g = CreateGadgetA((ULONG)DriPenAdjustGTypes[ lc ], g, &ng, ( struct TagItem * )&DriPenAdjustGTags[ tc ] );
  726.  
  727.     while( DriPenAdjustGTags[ tc ] ) 
  728.       tc += 2;
  729.  
  730.     tc++;
  731.     if ( NOT g )
  732.       return( (int) 0 );
  733.   } // for()
  734.  
  735.   if ( ! ( DriPenAdjustWnd = OpenWindowTags( NULL,
  736.     WA_Left,        wleft,
  737.     WA_Top,         wtop,
  738.     WA_Width,       ww + OffX + Scr->WBorRight,
  739.     WA_Height,      wh + OffY + Scr->WBorBottom,
  740.     WA_IDCMP,       PALETTEIDCMP|CYCLEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  741.     WA_Flags,       WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  742.     WA_Gadgets,     DriPenAdjustGList,
  743.     WA_Title,       DriPenAdjustWdt,
  744.     WA_PubScreen,   Scr,
  745.     WA_AutoAdjust,  TRUE,
  746.     TAG_DONE )))
  747.     return( (int) 0 );
  748.  
  749.   GT_RefreshWindow( DriPenAdjustWnd, NULL );
  750.   DriPenAdjustRender();
  751.   return( (int) 1 );
  752. }
  753. ///
  754.  
  755. /// CloseDriPenAdjustWindow( )
  756. void CloseDriPenAdjustWindow( void )
  757. {
  758.   if ( DriPenAdjustWnd )
  759.     CloseWindow( DriPenAdjustWnd );
  760.   if ( DriPenAdjustGList )
  761.     FreeGadgets( DriPenAdjustGList );
  762.   if ( DriPenAdjustFont )
  763.     CloseFont( DriPenAdjustFont );
  764.   
  765.   DriPenAdjustWnd     = NULL;
  766.   DriPenAdjustGList   = NULL;
  767.   DriPenAdjustFont    = NULL;
  768.  
  769.   updatescreen( );                  //  close screen, and reopen with new dripens
  770. }
  771. ///
  772.  
  773. /// ApplicationDataRender( )
  774. void ApplicationDataRender( void )
  775. {
  776.   ComputeFont( ApplicationDataWidth, ApplicationDataHeight );
  777.   RenderLine( ApplicationDataWnd->RPort, OffX + ComputeX( 0 ), OffY + ComputeY( 64 ), OffX+ComputeX( 202 ), OffY+ComputeY( 64 ) );
  778. }
  779. ///
  780.  
  781. /// HandleApplicationDataIDCMP( )             TO BE OPTIMIZED
  782. int HandleApplicationDataIDCMP( void )
  783. {
  784.   struct IntuiMessage     *m;
  785.   int                     (*func)();
  786.   BOOL                    running = TRUE;
  787.  
  788.   while( m = GT_GetIMsg( ApplicationDataWnd->UserPort )) {
  789.     CopyMem(( char * )m, ( char * )&ApplicationDataMsg, (long)sizeof( struct IntuiMessage ));
  790.     GT_ReplyIMsg( m );
  791.     switch ( ApplicationDataMsg.Class ) {
  792.       case    IDCMP_REFRESHWINDOW:
  793.                 GT_BeginRefresh( ApplicationDataWnd );
  794.                 ApplicationDataRender();
  795.                 GT_EndRefresh( ApplicationDataWnd, TRUE );
  796.               break;
  797.       case    IDCMP_CLOSEWINDOW:
  798.                 running = ApplicationDataCloseWindow();
  799.               break;
  800.       case    IDCMP_GADGETUP:
  801.                 func = ( void * )(( struct Gadget * )ApplicationDataMsg.IAddress )->UserData;
  802.                 running = func();
  803.               break;
  804.     }
  805.   }
  806.   return( (int) running );
  807. }
  808. ///
  809.  
  810. /// OpenApplicationDataWindow( )
  811. int OpenApplicationDataWindow( void )
  812. {
  813.   struct NewGadget        ng;
  814.   struct Gadget   *g;
  815.   UWORD           lc, tc;
  816.   UWORD           wleft = ApplicationDataLeft, wtop = ApplicationDataTop, ww, wh;
  817.  
  818.   ComputeFont( ApplicationDataWidth, ApplicationDataHeight );
  819.   ww = ComputeX( ApplicationDataWidth );
  820.   wh = ComputeY( ApplicationDataHeight );
  821.  
  822.   if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  823.   if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  824.  
  825.   if ( ! ( ApplicationDataFont = OpenDiskFont( Font )))
  826.     return( (int) 0 );
  827.   if ( ! ( g = CreateContext( &ApplicationDataGList )))
  828.     return( (int) 0 );
  829.  
  830.   for( lc = 0, tc = 0; lc < ApplicationData_CNT; lc++ ) {
  831.     CopyMem((char * )&ApplicationDataNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  832.     ng.ng_VisualInfo = VisualInfo;
  833.     ng.ng_TextAttr   = Font;
  834.     ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  835.     ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  836.     if ( ApplicationDataGTypes[ lc ] != GENERIC_KIND ) {
  837.       ng.ng_Width      = ComputeX( ng.ng_Width );
  838.       ng.ng_Height     = ComputeY( ng.ng_Height);
  839.     }
  840.     ApplicationDataGadgets[ lc ] = g = CreateGadgetA((ULONG)ApplicationDataGTypes[ lc ], g, &ng, ( struct TagItem * )&ApplicationDataGTags[ tc ] );
  841.     if ( ApplicationDataGTypes[ lc ] == GENERIC_KIND ) {
  842.       g->Flags             |= GFLG_GADGIMAGE | GFLG_GADGHIMAGE;
  843.       g->Activation        |= GACT_RELVERIFY;
  844.       g->GadgetRender       = (APTR)getImage;
  845.       g->SelectRender       = (APTR)getImage;
  846.     }
  847.     while( ApplicationDataGTags[ tc ] ) 
  848.       tc += 2;
  849.     tc++;
  850.     if ( NOT g )
  851.       return( (int) 0 );
  852.   } //  for()
  853.  
  854.   ApplicationDataGadgets[GD_appgetfile]->TopEdge =  ApplicationDataGadgets[0]->TopEdge + ApplicationDataGadgets[0]->Height - 14;
  855.  
  856.   if ( ! ( ApplicationDataWnd = OpenWindowTags( NULL,
  857.     WA_Left,        wleft,
  858.     WA_Top,         wtop,
  859.     WA_Width,       ww + OffX + Scr->WBorRight,
  860.     WA_Height,      wh + OffY + Scr->WBorBottom,
  861.     WA_IDCMP,       STRINGIDCMP|INTEGERIDCMP|BUTTONIDCMP|IDCMP_GADGETUP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  862.     WA_Flags,       WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  863.     WA_Gadgets,     ApplicationDataGList,
  864.     WA_Title,       ApplicationDataWdt,
  865.     WA_PubScreen,   Scr,
  866.     WA_AutoAdjust,  TRUE,
  867.     TAG_DONE )))
  868.     return( (int) 0 );
  869.  
  870.   GT_SetGadgetAttrs(ApplicationDataGadgets[GD_app_path],ApplicationDataWnd,NULL,GTST_String,AppName,TAG_END);
  871.   GT_SetGadgetAttrs(ApplicationDataGadgets[GD_apppri], ApplicationDataWnd, NULL,
  872.     GTIN_Number, AppPri, TAG_END);
  873.   GT_SetGadgetAttrs(ApplicationDataGadgets[GD_Gadget12],ApplicationDataWnd,NULL,
  874.     GTIN_Number, AppStack,TAG_END);
  875.  
  876.   GT_RefreshWindow( ApplicationDataWnd, NULL );
  877.   ApplicationDataRender();
  878.   return( (int) 1 );
  879. }
  880. ///
  881.  
  882. /// CloseApplicationDataWindow( )
  883. void CloseApplicationDataWindow( void )
  884. {
  885.   if ( ApplicationDataWnd )
  886.     CloseWindow( ApplicationDataWnd );
  887.   if ( ApplicationDataGList )
  888.     FreeGadgets( ApplicationDataGList );
  889.   if ( ApplicationDataFont )
  890.     CloseFont( ApplicationDataFont );
  891.  
  892.   ApplicationDataWnd    = NULL;
  893.   ApplicationDataGList  = NULL;
  894.   ApplicationDataFont   = NULL;
  895. }
  896. ///
  897.  
  898. /// ParseIconArgs( )
  899. //  reads tooltypes into global static vars, supported tooltypes are:
  900. //    APPNAME       the name of the application to start
  901. //    APPPRI        the taskpriority of the application to start
  902. //    APPSTACK      the stacksize of the app.
  903. //    APPARGS
  904. //    PUBNAME       Name of the public screen, which pubby will open.
  905. //    PUBTITLE      titlebar text of public screen
  906. //    SHOWNAME      yes / no display pubscreen name in title bar
  907. //    DEPTH         Number of colors the screen will have
  908. //    WIDTH         Width of screen
  909. //    HEIGHT        height of screen
  910. //    DISPLAYID     displayid of screenmode to open in
  911. //    FONTNAME      name of screen font
  912. //    FONTSIZE      size of the font
  913. //    POPSTART      YES / NO, popup the screenmode requester before opening the screen      *
  914. //    INTERLEAVED   YES / NO. screen uses interleaved bitmaps                               *
  915. //    SHANGHAI      YES / NO. open wb windows on screen or not                              *
  916. //    FQUIT         YES / NO. quit immediately afrer application has finished               *
  917. //    FWQUIT        YES / NO. quit immediately, after all windows are closed                *
  918. //
  919. //    * are only read, not written by Pubby
  920.  
  921. WORD  ParseIconArgs(  struct  WBStartup *wbs  )
  922. {
  923.     struct  DiskObject  *dobj;
  924.     UBYTE   **tarray;
  925.     UBYTE   *s;
  926.     register int  i = 0;
  927.     struct  rtScreenModeRequester *scrreq = NULL;
  928.  
  929.     BPTR  fptr  = NULL;       //  DOS stuff
  930.     UBYTE palname[250];       //  pathname of app-specific palette
  931.  
  932.     if(!wbs)
  933.       return((WORD)0);
  934.  
  935.     CurrentDir(wbs->sm_ArgList->wa_Lock);
  936.  
  937.     if(dobj = GetDiskObject(wbs->sm_ArgList->wa_Name))
  938.     {
  939.       tarray = (char  **) dobj->do_ToolTypes;
  940.  
  941.       if( s = FindToolType( tarray, "PUBNAME"  ))
  942.         strncpy(  PubScrName, s, 20 );
  943.       if( s = FindToolType( tarray, "APPNAME" ))
  944.         strncpy(  AppName, s, 200 );
  945.       if( s = FindToolType( tarray, "APPPRI"  ))
  946.         AppPri  = atol(s);
  947.       else
  948.         AppPri  = 0;
  949.       if( s = FindToolType( tarray, "APPSTACK"  ))
  950.         AppStack  = atol( s );
  951.       else
  952.         AppStack  = 4096;
  953.  
  954.       if( s = FindToolType( tarray, "FQUIT" ))
  955.         if(strcmp(s,"YES")==0)
  956.           FQUIT=TRUE;
  957.         else
  958.           FQUIT=FALSE;
  959.  
  960.       if( s = FindToolType( tarray, "FWQUIT" ))
  961.         if(strcmp(s,"YES")==0){
  962.           FWQUIT=TRUE;
  963.           FQUIT =FALSE;
  964.         }
  965.         else
  966.           FWQUIT=FALSE;
  967.  
  968.       if( s = FindToolType( tarray, "APPARGS" ))
  969.         strncpy(App_Args, s, 200);
  970.  
  971.       if( s = FindToolType( tarray, "PUBNAME" ))
  972.         strncpy(PubScrName, s, 20);
  973.  
  974.       if( s = FindToolType( tarray, "PUBTITLE" ))
  975.         strncpy(PubTitle, s, 100);
  976.  
  977.       if( s = FindToolType( tarray, "DEPTH" ))
  978.         Depth = atol( s );
  979.       else
  980.         Depth = 2;    //  4 colors default
  981.       if( s = FindToolType( tarray, "WIDTH" ))
  982.         Width = atol( s );
  983.       else
  984.         Width = 640;
  985.       if( s = FindToolType( tarray, "HEIGHT" ))
  986.         Height = atol( s );
  987.       else
  988.         Height = 256;
  989.       if( s = FindToolType( tarray, "DISPLAYID" )){
  990.         if( atol ( s ) != 0 ){
  991.           ID = atol( s );
  992.         }
  993.       }
  994.       else
  995.         ID = DEFAULT_MONITOR_ID|LORES_KEY;
  996.       if( s = FindToolType( tarray, "FONTNAME"  )){
  997.         if(strlen(s)>30)
  998.           strncpy( FONTNAME, s, 30 );
  999.         else
  1000.           strcpy( FONTNAME, s);
  1001.       }
  1002.       else
  1003.         strcpy( FONTNAME, "topaz.font");
  1004.       if( s = FindToolType( tarray, "FONTSIZE"  ))
  1005.         FONTSIZE = (UWORD) atol( s );
  1006.       else
  1007.         FONTSIZE = 8;
  1008.       for(i=0;i<=11;i++)    //  The Dri Pen definitions
  1009.         if( s = FindToolType( tarray, TTARRAY[i]  ))
  1010.           DriPens[i] = atol( s );
  1011.  
  1012.       if( s = FindToolType( tarray, "INTERLEAVED" )){
  1013.         if(strcmp(  s , "YES")  ==0)
  1014.           INTERLEAVED=TRUE;
  1015.         else
  1016.           INTERLEAVED=FALSE;
  1017.       }
  1018.  
  1019.       if( s = FindToolType( tarray, "SHANGHAI" )) {
  1020.         if(strcmp(  s , "YES")  ==0)
  1021.           _SHANGHAI=TRUE;
  1022.         else
  1023.           _SHANGHAI=FALSE;
  1024.       }
  1025.  
  1026.       if( s = FindToolType( tarray, "SHOWNAME" )) {
  1027.         if(strcmp(  s , "YES")  ==0)
  1028.           SHOWNAME=TRUE;
  1029.         else
  1030.           SHOWNAME=FALSE;
  1031.       }
  1032.  
  1033.       if( s = FindToolType( tarray, "POPSTART" )) {
  1034.         if(strcmp(s,"YES")==0){
  1035.           if(scrreq = (struct rtScreenModeRequester *)                //  on default pub screen (wb)
  1036.             rtAllocRequestA( RT_SCREENMODEREQ, NULL ) ) {
  1037.             if(rtScreenModeRequest( scrreq, "Select a mode...",RTSC_Flags,
  1038.               SCREQF_DEPTHGAD|SCREQF_SIZEGADS|SCREQF_GUIMODES,TAG_END)){
  1039.  
  1040.               //  screenmode selected, copy parameters...
  1041.               ID          = scrreq->DisplayID;
  1042.               Width       = scrreq->DisplayWidth;
  1043.               Height      = scrreq->DisplayHeight;
  1044.               Depth       = scrreq->DisplayDepth;
  1045.  
  1046.             }   //  if rtScreenRequest()
  1047.             rtFreeRequest(scrreq);   //  free allocated memory
  1048.           } //  no mem
  1049.           else
  1050.             rtEZRequest("PubIt-Error:\nNo memory for requester!","OK!",0l,0l);
  1051.         } //  if POPSTART == YES
  1052.       } //  if POPSTART is found as tt
  1053.   
  1054.       FreeDiskObject( dobj );
  1055.  
  1056.       //  read palette
  1057.  
  1058.       if(strlen(AppName)<=0){
  1059.         if( fptr = Open("ENVARC:PubIt.palette",MODE_OLDFILE) ){
  1060.           for(i=0;i<768;i++)
  1061.             Read(fptr, (UBYTE *)&mycolors[i], sizeof (UBYTE) );
  1062.           Close(fptr);
  1063.         }
  1064.         //  else, no default palette saved !
  1065.       }
  1066.       else{
  1067.         sprintf(palname,"%s.pal",AppName);
  1068.         if( fptr =  Open(palname,MODE_OLDFILE ) ){
  1069.           for(i=0;i<768;i++)
  1070.             Read(fptr, (UBYTE *)&mycolors[i], sizeof (UBYTE) );
  1071.           Close(fptr);
  1072.         }
  1073.       }
  1074.       return((WORD)1);
  1075.     }
  1076.     else{
  1077.       rtEZRequest("PubIt-Error:\nCan't read Icon-Tooltypes!","Shit!",0l,0l);    //  no screen open, yet
  1078.       return((WORD)0);
  1079.     }
  1080. }
  1081. ///
  1082.  
  1083. /// ReplaceTool( )
  1084. static BOOL ReplaceTool(UBYTE **ttarr, UBYTE *ts, UBYTE *rps)
  1085. {
  1086.         WORD a = 0;
  1087.  
  1088.         while (ttarr[a])
  1089.         {
  1090.                 if (strnicmp(ttarr[a], ts, strlen(ts)) == 0)
  1091.                 {
  1092.                         ttarr[a] = rps;
  1093.                         return FALSE;
  1094.                 }
  1095.                 a++;
  1096.         }
  1097.         return TRUE;
  1098. }
  1099. ///
  1100.  
  1101. /// SaveCurrSettings( )
  1102. //  writes actual settings into tooltypes...
  1103. //  supported tooltypes, see above
  1104.  
  1105. WORD  SaveCurrSettings( struct  WBStartup * wbs )
  1106. {
  1107.   struct  DiskObject  *dobj;
  1108.   static UBYTE  buffer[23][512];
  1109.   UBYTE   **oldtooltypes, **tarray;
  1110.   register int  i = 0;
  1111.  
  1112.   BPTR  fptr  = NULL;                         //  dos stuff
  1113.   UBYTE palname[250];                         //  app-specific palette
  1114.  
  1115.   if(!wbs)
  1116.     return((WORD)0);
  1117.  
  1118.   if(strlen(AppName)<=0){
  1119.     i=rtEZRequestTags("No AppName given.\nShall I save palette as default?","Yes|No",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1120.     if(i){
  1121.       if(!(fptr=Open("ENVARC:PubIt.palette",MODE_NEWFILE))){
  1122.         rtEZRequestTags("PubIt-Error:\nCan't open \"ENVARC:PubIt.palette\"\nfor write access!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1123.         return((int)0);
  1124.       }
  1125.       for(i=0;i<768;i++)
  1126.         Write(fptr, &mycolors[i], sizeof(UBYTE) );
  1127.       Close(fptr);
  1128.       fptr=NULL;
  1129.     }   //  if
  1130.   }
  1131.   else  {       //  palette for that specific application
  1132.     sprintf(palname,"%s.pal",AppName);
  1133.     if(!(fptr=Open(palname,MODE_NEWFILE))){
  1134.       rtEZRequestTags("PubIt-Error:\nCan't write \"%s\"!","Shit!",0l,palname,RT_PubScrName,PubScrName,TAG_END);
  1135.       return((int)0);
  1136.     }
  1137.     for(i=0;i<768;i++)
  1138.       Write(fptr, &mycolors[i], sizeof(UBYTE) );
  1139.     Close(fptr);
  1140.     fptr=NULL;
  1141.   }
  1142.  
  1143.   CurrentDir(wbs->sm_ArgList->wa_Lock);
  1144.  
  1145.   if( dobj =  GetDiskObject(  wbs->sm_ArgList->wa_Name  ))
  1146.   {
  1147.     tarray  = (char **) dobj->do_ToolTypes;
  1148.  
  1149.     for(i=0;i<=11;i++)
  1150.     {
  1151.       sprintf( buffer[i], "%s=%ld",  TTARRAY[i], DriPens[i] );
  1152.       ReplaceTool( tarray,  TTARRAY[i], (UBYTE*)&buffer[i] );
  1153.     }
  1154.  
  1155.     sprintf( buffer[12], "PUBNAME=%s",PubScrName);
  1156.     ReplaceTool( tarray,  "PUBNAME" , (UBYTE*)&buffer[12] );
  1157.     sprintf( buffer[12], "PUBTITLE=%s",PubTitle);
  1158.     ReplaceTool( tarray,  "PUBNAME" , (UBYTE*)&buffer[22] );
  1159.     sprintf( buffer[13], "APPNAME=%s",AppName);
  1160.     ReplaceTool( tarray,  "APPNAME" , (UBYTE*)&buffer[13] );
  1161.     sprintf( buffer[14],  "APPPRI=%ld", AppPri);
  1162.     ReplaceTool( tarray,  "APPPRI" , (UBYTE*)&buffer[14] );
  1163.     sprintf( buffer[15],  "APPSTACK=%ld", AppStack);
  1164.     ReplaceTool( tarray,  "APPSTACK" , (UBYTE*)&buffer[15] );
  1165.     sprintf( buffer[16], "DEPTH=%ld",  Depth);
  1166.     ReplaceTool( tarray,  "DEPTH" , (UBYTE*)&buffer[16] );
  1167.     sprintf( buffer[17], "WIDTH=%ld",  Width);
  1168.     ReplaceTool( tarray,  "WIDTH" , (UBYTE*)&buffer[17] );
  1169.     sprintf( buffer[18],  "HEIGHT=%ld", Height);
  1170.     ReplaceTool( tarray,  "HEIGHT" , (UBYTE*)&buffer[18] );
  1171.     sprintf( buffer[19],  "DISPLAYID=%ld",  ID  );
  1172.     ReplaceTool( tarray,  "DISPLAYID" , (UBYTE*)&buffer[19] );
  1173.     sprintf( buffer[20],  "FONTNAME=%s", FONTNAME );
  1174.     ReplaceTool( tarray, "FONTNAME", (UBYTE*)&buffer[20] );
  1175.     sprintf( buffer[21], "FONTSIZE=%ld", FONTSIZE );
  1176.     ReplaceTool( tarray, "FONTSIZE", (UBYTE *)&buffer[21] );
  1177.  
  1178.     oldtooltypes  = dobj->do_ToolTypes;
  1179.     dobj->do_ToolTypes = tarray;
  1180.  
  1181.     if(!PutDiskObject(wbs->sm_ArgList->wa_Name, dobj)){
  1182.       rtEZRequestTags("PubIt-Error:\nCan't write Icon-Tooltypes","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1183.       dobj->do_ToolTypes  = oldtooltypes;
  1184.       FreeDiskObject( dobj );
  1185.       return((WORD)0);
  1186.     }
  1187.     else
  1188.       FreeDiskObject( dobj );
  1189.   }
  1190.   else{
  1191.     rtEZRequestTags("PubIt-Error:\nCan't read Icon-Tooltypes!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1192.     return((WORD)0);
  1193.   }
  1194.   return((WORD)1);    //  ok, successfully written
  1195. }
  1196. ///
  1197.  
  1198. /// closeall( )
  1199. void  closeall( void )
  1200. {
  1201.   //  Libs Stuff
  1202.   if(IconBase)      CloseLibrary(IconBase);
  1203.   if(DiskfontBase)  CloseLibrary(DiskfontBase);
  1204.   if(GadToolsBase)  CloseLibrary(GadToolsBase);
  1205.   if(GfxBase)       CloseLibrary((struct  Library *)GfxBase);
  1206.   if(IntuitionBase) CloseLibrary(IntuitionBase);
  1207.   if(ReqToolsBase)  CloseLibrary(ReqToolsBase);
  1208.   exit(0);
  1209. }
  1210. ///
  1211.  
  1212. /// openall( )
  1213. void  openall( void )
  1214. {
  1215.   //  Libs Stuff
  1216.   if(ReqToolsBase = OpenLibrary("reqtools.library", 38))
  1217.     if(IntuitionBase = OpenLibrary("intuition.library", 39))
  1218.       if(GfxBase = (struct  GfxBase *)OpenLibrary("graphics.library", 39))
  1219.         if(GadToolsBase = OpenLibrary("gadtools.library", 39))
  1220.           if(DiskfontBase = OpenLibrary("diskfont.library", 39))
  1221.             if(IconBase = OpenLibrary("icon.library", 39))
  1222.               return;
  1223.         else
  1224.               rtEZRequest("Icon Library V39+ required!","OK!",0l,0l);
  1225.           else
  1226.             rtEZRequest("Diskfont Library V39+ required!","OK!",0l,0l);
  1227.         else
  1228.           rtEZRequest("GadTools Library V39+ required!","OK!",0l,0l);
  1229.       else
  1230.         rtEZRequest("Graphics Library V39+ required!","OK!",0l,0l);
  1231.     else
  1232.       rtEZRequest("Intuition Library V39+ required!","OK!",0l,0l);
  1233.   else
  1234.     puts("ReqTools Library V38+ required!\n");
  1235.  
  1236.   closeall( );   // failed, quit.
  1237. }
  1238. ///
  1239.  
  1240. /// updatescreen( )
  1241. int updatescreen( void )
  1242. {
  1243.   int success = 0;
  1244.  
  1245.   ClosePubbyMainWindow( );
  1246.   CloseDownScreen( );
  1247.  
  1248.   success=SetupScreen( );
  1249.   if(success!=1){                   //  FATAL ERROR: can't reopen screen
  1250.     rtEZRequest("PubIt-Error:\nUnable to reopen screen in\nspecified mode. PubIt quits!","Shit!",0l,0l);
  1251.     closeall( );
  1252.     exit(0);            //  no special messy to dos, does somebody care?
  1253.   }
  1254.  
  1255.   success=OpenPubbyMainWindow( );  //  try to reopen window
  1256.   if(success!=1){
  1257.     rtEZRequestTags("PubIt-Error:\nUnable to reopen window.","Quit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1258.     CloseDownScreen( );
  1259.     closeall( );
  1260.     exit(0);            //  no special messy to dos, does somebody care?
  1261.   }
  1262.   ActivateWindow(PubbyMainWnd);
  1263.   return((int)1);
  1264. }
  1265. ///
  1266.  
  1267. // SubFunctions  --------------------
  1268.  
  1269. /// driadjust subs
  1270. int driadjust_paletteClicked( void )
  1271. { /* routine when gadget "_Color" is clicked. */
  1272.  
  1273.   DriPens[SelectedDriPen] = DriPenAdjustMsg.Code ;
  1274.   SetAPen(DriPenAdjustWnd->RPort, (long) DriPens[SelectedDriPen] );
  1275.   RectFill(DriPenAdjustWnd->RPort, OffX + ComputeX( 178 )+2 ,OffY + ComputeY( 30 )+1 ,
  1276.   OffX + ComputeX( 178 ) + ComputeX( 27 ) -3  ,
  1277.   OffY + ComputeY( 30 )+2 + ComputeY( 25 )-4 );
  1278.   
  1279.   return((int) 0 );
  1280. }
  1281.  
  1282. int driadjust_pensClicked( void )
  1283. { /* routine when gadget "_Pens" is clicked. */
  1284.  
  1285.   SelectedDriPen = (int) DriPenAdjustMsg.Code;
  1286.   SetAPen(DriPenAdjustWnd->RPort, (long) DriPens[SelectedDriPen] );
  1287.   RectFill(DriPenAdjustWnd->RPort, OffX + ComputeX( 178 )+2 ,OffY + ComputeY( 30 )+1 ,
  1288.   OffX + ComputeX( 178 ) + ComputeX( 27 ) -3  ,
  1289.   OffY + ComputeY( 30 )+2 + ComputeY( 25 )-4 );
  1290.   return((int) 0 );
  1291. }
  1292.  
  1293. int driadjust_OKClicked( void )
  1294. { /* routine when gadget "_OK" is clicked. */
  1295.   return((int) -1 );
  1296. }
  1297. ///
  1298.  
  1299. /// app subs
  1300. int app_pathClicked( void )
  1301. { /* routine when gadget "_Path/File:" is clicked. */
  1302.   strcpy(AppName, GetString(ApplicationDataGadgets[GD_app_path]) );
  1303.   return((int) 0 );
  1304. }
  1305.  
  1306. int Gadget12Clicked( void )
  1307. { /* routine when gadget "_Stack:" is clicked. */
  1308.   AppStack = (long)  GetNumber( ApplicationDataGadgets[GD_Gadget12] ) ;
  1309.   return((int) 0 );
  1310. }
  1311.  
  1312. int apppriClicked( void )
  1313. { /* routine when gadget "_Priority:" is clicked. */
  1314.   AppPri = (long)  GetNumber( ApplicationDataGadgets[GD_apppri] ) ;
  1315.   return((int) 0 );
  1316. }
  1317.  
  1318. int appokClicked( void )
  1319. { /* routine when gadget "_OK" is clicked. */
  1320.   return((int) -1 );
  1321. }
  1322.  
  1323. int appgetfileClicked( void )
  1324. { /* routine when gadget "" is clicked. */
  1325.  
  1326.   UBYTE filename[108];
  1327.   UBYTE path[108];
  1328.   struct  rtFileRequester *freq = NULL;
  1329.  
  1330.   filename[0] = (UBYTE) 0;
  1331.   path[0] = (UBYTE) 0;
  1332.  
  1333.   if(!( GetCurrentDirName( (STRPTR) path, 108 ) ) )
  1334.     strcpy(path, "SYS:");
  1335.  
  1336.   if(!( freq = (struct  rtFileRequester *)rtAllocRequestA( RT_FILEREQ,NULL ) ) ){
  1337.     rtEZRequestTags("PubIt-Error:\nNo memory for file requester!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1338.     return((int) 0);
  1339.   }
  1340.  
  1341.   rtChangeReqAttr( (APTR)freq, RTFI_Dir, path, TAG_END);
  1342.  
  1343.   if(!( rtFileRequest( freq, filename, "Select Application",
  1344.     RTFI_Flags, FREQF_PATGAD, RT_PubScrName,PubScrName,TAG_END ) ) ){
  1345.     return( (int) 0 );        //  user didn't select s.th.
  1346.   }
  1347.  
  1348.   strcpy(path, freq->Dir);
  1349.   
  1350.   if(path[strlen(path)-1]!=':' && path[strlen(path)-1]!='/')
  1351.     strcat(path,"/");
  1352.   strcat(path,filename);
  1353.  
  1354.   rtFreeRequest(freq);
  1355.  
  1356.   strcpy(AppName, path);
  1357.   GT_SetGadgetAttrs(ApplicationDataGadgets[GD_app_path],ApplicationDataWnd,NULL,GTST_String,AppName,TAG_END);
  1358.   return((int) 1 );
  1359. }
  1360. ///
  1361.  
  1362. /// main subs
  1363. int PubbyMainsmode( void )
  1364. { /* routine when (sub)item "Screen Mode..." is selected. */
  1365.  
  1366.   struct  rtScreenModeRequester *scrreq = NULL;
  1367.   int success = 0;
  1368.  
  1369.   if(scrreq = (struct rtScreenModeRequester *)
  1370.     rtAllocRequestA( RT_SCREENMODEREQ, NULL ) ) {
  1371.  
  1372.     if(rtScreenModeRequest( scrreq, "Select a mode...",RTSC_Flags,
  1373.       SCREQF_DEPTHGAD|SCREQF_SIZEGADS|SCREQF_GUIMODES,RT_PubScrName,PubScrName,TAG_END)){
  1374.  
  1375.       //  screenmode selected, copy parameters...
  1376.       ID          = scrreq->DisplayID;
  1377.       Width       = scrreq->DisplayWidth;
  1378.       Height      = scrreq->DisplayHeight;
  1379.       Depth       = scrreq->DisplayDepth;
  1380.  
  1381.       ClosePubbyMainWindow();
  1382.   WinPoint:
  1383.       if(CloseDownScreen()!=1){
  1384.         rtEZRequestTags("Please close all windows,\nthen click \"Retry!\"","Retry!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1385.         goto WinPoint;
  1386.       }
  1387.  
  1388.       success=SetupScreen( );
  1389.       if(success!=1){                   //  FATAL ERROR: can't reopen screen
  1390.         rtEZRequest("PubIt-Error:\nUnable to reopen screen in\nspecified mode. PubIt quits!","Shit!",0l,0l);
  1391.         rtFreeRequest(scrreq);
  1392.         closeall( );
  1393.         exit(0);            //  no special messy to dos, does somebody care?
  1394.       }
  1395.  
  1396.       success=OpenPubbyMainWindow( );  //  try to reopen window
  1397.       if(success!=1){
  1398.         rtEZRequestTags("PubIt-Error:\nUnable to reopen window.","Quit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1399.         CloseDownScreen( );
  1400.         rtFreeRequest(scrreq);   //  free allocated memory
  1401.         closeall( );
  1402.         exit(0);            //  no special messy to dos, does somebody care?
  1403.       }
  1404.     }   //  if rtScreenRequest()
  1405.     rtFreeRequest(scrreq);   //  free allocated memory
  1406.     return((int)1);     //  succeeded
  1407.   } //  no mem
  1408.   else
  1409.     rtEZRequestTags("PubIt-Error:\nNo memory for requester!","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1410.   ActivateWindow(PubbyMainWnd);
  1411.   return((int)0);
  1412. }
  1413.  
  1414. int PubbyMaincpalette( void )
  1415. { /* routine when (sub)item "Color-Palette..." is selected. */
  1416.   rtPaletteRequest( (char*)"Color-Palette", NULL, RT_PubScrName, PubScrName, TAG_END );
  1417.   getcolors( );
  1418.   return((int) 0 );
  1419. }
  1420.  
  1421. int PubbyMainappdata( void )
  1422. {
  1423.   if( OpenApplicationDataWindow( ) == 1 )
  1424.     while(HandleApplicationDataIDCMP( ) != -1 )
  1425.       ;
  1426.   CloseApplicationDataWindow( );
  1427.   return((int) 0 );
  1428. }
  1429.  
  1430. int PubbyMaindripens( void )
  1431. { /* routine when (sub)item "Define DriPens..." is selected. */
  1432.  
  1433.   if( OpenDriPenAdjustWindow( ) == 1 )
  1434.     while(HandleDriPenAdjustIDCMP( ) != -1 )
  1435.       ;
  1436.   CloseDriPenAdjustWindow( );
  1437.   return((int) 0 );
  1438. }
  1439.  
  1440. int PubbyMainfont( void )
  1441. { /* routine when (sub)item "Font..." is selected. */
  1442.   struct  rtFontRequester *fontreq=0L;
  1443.  
  1444.   if(fontreq=(struct rtFontRequester*)rtAllocRequestA(RT_FONTREQ,NULL)){
  1445.     fontreq->Flags=FREQF_SCALE;
  1446.     if(rtFontRequest(fontreq,"Select Font...", RT_PubScrName,PubScrName,TAG_END)){
  1447.         strcpy(FONTNAME,fontreq->Attr.ta_Name);
  1448.         FONTSIZE=fontreq->Attr.ta_YSize;
  1449.     }
  1450.     else{
  1451.       rtFreeRequest(fontreq);
  1452.       return((int)  0);
  1453.     }
  1454.     rtFreeRequest(fontreq);
  1455.     fontreq=0L;
  1456.   }
  1457.   
  1458.   //  new font selected
  1459.   
  1460.   ClosePubbyMainWindow( );
  1461.   CloseDownScreen( );
  1462.  
  1463.   ScrAttr.ta_Name   = (STRPTR) NULL;
  1464.   ScrAttr.ta_YSize  = 0;
  1465.  
  1466.   if(SetupScreen( ) == 1  )
  1467.     if(OpenPubbyMainWindow( ) == 1)
  1468.       return((int)1);
  1469.     else
  1470.       rtEZRequestTags("PubIt-Error:\nUnable to reopen Window!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1471.   else
  1472.     rtEZRequest("PubIt-Error:\nUnable to reopen Screen!","Shit!",0l,0l);
  1473.  
  1474.   if(Scr)
  1475.     CloseDownScreen( );
  1476.   closeall( );
  1477.   exit(0);
  1478. }
  1479.  
  1480. int PubbyMainabout( void )
  1481. { /* routine when (sub)item "About" is selected. */
  1482.   rtEZRequestTags("PubIt 1.01\nCopyright © 1994 by Chris (Confusio) Rickers\n\nThis is Cardware (if you like it, send me a postcard)","I see!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1483.   return((int) 0 );
  1484. }
  1485.  
  1486. int PubbyMainsave( void )
  1487. { /* routine when (sub)item "Save..." is selected. */
  1488.   if(!(SaveCurrSettings(IconArgs)==1))
  1489.     rtEZRequestTags("PubIt-Error:\nCan't write tooltypes, no data saved.","OK!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1490.   return((int) 0 );
  1491. }
  1492.  
  1493. int PubbyMainquit( void )
  1494. { /* routine when (sub)item "Quit." is selected. */
  1495.   return((int) -1 );
  1496. }
  1497.  
  1498. int PubbyMainCloseWindow( void )                  //  this won't be called, due to borderless window without close gadget
  1499. { /* routine for "IDCMP_CLOSEWINDOW". */
  1500.   return((int) -1 );
  1501. }
  1502. ///
  1503.  
  1504. /// gui subs
  1505. int DriPenAdjustCloseWindow( void )
  1506. { /* routine for "IDCMP_CLOSEWINDOW". */
  1507.   return((int) -1 );
  1508. }
  1509.  
  1510. int ApplicationDataCloseWindow( void )
  1511. { /* routine for "IDCMP_CLOSEWINDOW". */
  1512.   return((int) -1 );
  1513. }
  1514. ///
  1515.  
  1516. // main program ----------------
  1517.  
  1518. void  main( int argc, char  **argv)
  1519. {
  1520.   short success = 0;
  1521.  
  1522.   openall( );
  1523.  
  1524.   if(argc==0)  //  started from wb
  1525.     IconArgs  = (struct WBStartup *)argv;
  1526.   else{
  1527.     rtEZRequest("Sorry, PubIt must be started from Workbench!","I'll try",0l,0l);
  1528.     exit(0);
  1529.   }
  1530.  
  1531.   if(!(ParseIconArgs(IconArgs)==1))
  1532.     rtEZRequest("Using defaults!","OK!",0l,0l);
  1533.  
  1534.   if(!(SetupScreen( ) == 1 ))
  1535.   {
  1536.     rtEZRequest("PubIt-Error:\nUnable to open requested Screen!","Shit!",0l,0l);
  1537.     goto EndPubby;
  1538.   }
  1539.   else
  1540.   {
  1541.     if(!(OpenPubbyMainWindow( ) == 1  )){
  1542.       rtEZRequestTags("PubIt-Error:\nUnable to open main backdrop window!","Shit!",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1543.       CloseDownScreen( );
  1544.       goto EndPubby;
  1545.     }
  1546.     else  {
  1547.  
  1548.       //  if application is specified, start it...
  1549.       ClearMenuStrip(PubbyMainWnd);
  1550.       RunApp( );  
  1551.       SetMenuStrip(PubbyMainWnd, PubbyMainMenus);
  1552.       if(FQUIT)
  1553.         goto pubbyex;
  1554.       if(FWQUIT) {
  1555.         //  wait until the first custom window is opened on pubby screen
  1556.         while(!(Scr->FirstWindow->NextWindow))
  1557.           Delay(100L);
  1558.  
  1559.         //  now wait until last non pubby window is closed
  1560.  
  1561.             //  *******************************************************************
  1562.             //   if s.o likes to, here is room for improvement:                   *
  1563.             //   NOTE: this is a busy loop, it's better to use signal ports and   *
  1564.             //         check it this way.                                         *
  1565.             //         but I have a fast system ... (and no time...!)             *
  1566.             //  *******************************************************************
  1567.  
  1568.         while(Scr->FirstWindow->NextWindow)
  1569.           ;
  1570.         goto pubbyex;
  1571.       }
  1572.       while( ! ( success = (short) HandlePubbyMainIDCMP( ) == -1 ) )         //  pubby idcmp parser
  1573.         ;
  1574.     }
  1575.     if(!(SaveCurrSettings(IconArgs)==1))
  1576.       rtEZRequestTags("Seems you need to specify the tooltypes next time again, Hö!","Blabla",0l,0l,RT_PubScrName,PubScrName,TAG_END);
  1577.  
  1578. pubbyex:
  1579.     ClosePubbyMainWindow( );
  1580.     CloseDownScreen( );
  1581.   }
  1582.  
  1583. EndPubby:
  1584.   closeall( );
  1585. }
  1586.  
  1587.  
  1588.